package com.lishe.lishe.lishe.module.recharge.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lishe.lishe.R;
import com.lishe.lishe.lishe.MyRecyclerView.RecyclerviewBaseAdapter;
import com.lishe.lishe.lishe.module.recharge.bean.RechargeRecord;
import com.lishe.lishe.lishe.utils.TimeUtils;

import java.util.List;

/**
 * Created by yang on 2018/3/8.
 */

public class RechargeRecordAdapter extends RecyclerviewBaseAdapter {

    private List<RechargeRecord> mList;

    public RechargeRecordAdapter( List<RechargeRecord> list) {
        this.mList = list;
    }

    @Override
    public MyViewHolder onCreateViewHolderMy(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_activity_recharge_record, null);
        MyViewHolder holder = new MyViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolderMy(RecyclerView.ViewHolder holder, int position) {
        RechargeRecord record=mList.get(position);
        ((MyViewHolder)holder).pay_count.setText(record.getMoney()*100+" 积分");
        ((MyViewHolder)holder).pay_type.setText("充值▪"+record.getStatus_message()+"["+record.getPay_name()+"]");
        if(record.getPayed_time()==null){

        }else{
            try {
                long time = Long.parseLong(record.getPayed_time());
                ((MyViewHolder) holder).pay_time.setText(TimeUtils.longToyyyyMMddHHmmss(time));
            }catch (NumberFormatException exception){
                exception.printStackTrace();
                ((MyViewHolder) holder).pay_time.setText(record.getPayed_time());
            }
        }

        ((MyViewHolder)holder).pay_num.setText("单号："+record.getPayment_id());
    }

    @Override
    public int getItemCountMy() {
        return mList.size();
    }

    @Override
    public int getItemViewTypeMy(int position) {
        return 0;
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        TextView pay_type,pay_count,pay_time,pay_num;
        public MyViewHolder(View itemView) {
            super(itemView);
            pay_type= itemView.findViewById(R.id.pay_type);
            pay_count= itemView.findViewById(R.id.pay_count);
            pay_time= itemView.findViewById(R.id.pay_time);
            pay_num= itemView.findViewById(R.id.pay_num);
        }
    }
}
